package cn.stylefeng.guns.modular.util.itext;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;

import java.io.IOException;

/**
 * @Description:
 * @Author jzy
 * @Date 2020/5/16 0016
 **/
public class Watermark extends PdfPageEventHelper {
    BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
    Font font = new Font(baseFont, 30, Font.BOLD, new GrayColor(0.95f));
    Font font20 = new Font(baseFont, 20, Font.BOLD, new GrayColor(0.95f));
    private String waterCont;//水印内容
    public Watermark() throws IOException, DocumentException {

    }
    public Watermark(String waterCont) throws IOException, DocumentException {
        this.waterCont = waterCont;
    }

    @Override
    public void onEndPage(PdfWriter writer, Document document) {
        for(int i=0 ; i<5; i++) {
            for(int j=0; j<5; j++) {
                ColumnText.showTextAligned(writer.getDirectContentUnder(),
                        Element.ALIGN_CENTER,
                        new Phrase("车 妥 妥", font),
                        (120.5f+i*350),
                        (140.0f+j*150),
                        writer.getPageNumber() % 2 == 1 ? 45 : 45);
                ColumnText.showTextAligned(writer.getDirectContentUnder(),
                        Element.ALIGN_CENTER,
                        new Phrase("www.chetuotuo.net", font20),
                        (120.5f+i*350 +10),
                        (140.0f+j*150 -15),
                        writer.getPageNumber() % 2 == 1 ? 45 : 45);
            }
        }
    }
}
